<template>
  <el-dialog title="充值记录" :visible="value" width="900px" custom-class="dialog-box" @close="onClose" @open="onOpen" :close-on-click-modal="false" :append-to-body="true">
    <table class="table-box printOrder-data">
      <thead>
        <tr>
          <th>操作类型</th>
          <th>操作时间</th>
          <!-- <th>收费方式</th> -->
          <!-- <th>原有金额</th> -->
          <th>本次赠送</th>
          <th>累计赠送</th>
          <th>账户余额</th>
          <th>积分</th>
          <th>备注</th>
          <th>操作人员</th>
        </tr>
      </thead>
      <tbody>
        <tr v-if="tableList.length>0" v-for="(item,index) in tableList" :key="index">
          <td>
            <span v-if="item.type==1">充值</span>
            <span v-else-if="item.type==2">退款</span>
            <span v-else>提现</span>
          </td>
          <td>{{item.gmtCreate}}</td>
          <!-- <td>{{item.type==1?"充值":"提现"}}</td> -->
          <!-- <td>{{item.beforeMoney}}</td> -->
          <td>{{item.freeGiveMoney}}</td>
          <td>{{item.afterGiveMoney}}</td>
          <td>{{item.afterMoney}}</td>
          <td>{{item.record}}</td>
          <td>{{item.desc}}</td>
          <td>{{item.memberName}}</td>
        </tr>
        <tr v-if="tableList.length<1">
          <td colspan="11" style="text-align:center;">暂无数据</td>
        </tr>
      </tbody>
    </table>
    <br />
    <el-row>
      <el-col :span="12" style="height:10px;"></el-col>
      <el-col :span="12">
        <!-- <el-button  style="float:right" v-if="tableList.length>0" @click="printPay">打印</el-button> -->
        <el-button style="float:right;margin-right:10px;" @click="exportExcel()">导出</el-button>
      </el-col>
    </el-row>
    <br />
    <pager v-model="pager" @change-pagenum="getRrcordList"></pager>
    <!-- <recharge v-if="showRecharge"></recharge> -->
  </el-dialog>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  props: ["value", "curItem"],
  data() {
    return {
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tableList: [],
      showRecharge: false
    };
  },
  mounted() {
    let th = this;
    th.getRrcordList();
  },
  methods: {
    getRrcordList() {
      let th = this;
      let j = { patientId: th.curItem.patientId, hpId: th.adminUser.hpId };
      Object.assign(j, th.pager);
      th.$api.getRechargeRecord(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
      });
    },
    onOpen() {},
    onClose() {
      let th = this;
      th.$emit("input", false);
    },
    //打印
    printPay() {
      let th = this;
      th.showRecharge = true;
      // let th=this;
      // window.document.body.innerHTML = document.getElementsByClassName("printOrder-data")[0].innerHTML;
      // window.print();
      // window.location.reload();
    },
    exportExcel() {
      let th = this;
      let data = [];
      th.$api
        .getRechargeRecord({
          patientId: th.curItem.patientId,
          hpId: th.adminUser.hpId
        })
        .then(res => {
          if (res.executed) {
            data = res.dataBody.list;
            Excel(
              data,
              [
                {
                  key: "type",
                  enum: { 1: "充值", 0: "提现", 2: "退款" },
                  type: "enum",
                  name: "操作类型"
                },
                { key: "gmtCreate", name: "操作时间" },
                // { key: "beforeMoney", name: "原有金额" },
                { key: "freeGiveMoney", name: "本次赠送" },
                { key: "afterGiveMoney", name: "累计赠送" },
                { key: "afterMoney", name: "账户余额" },
                { key: "record", name: "积分" },
                { key: "desc", name: "备注" },
                { key: "memberName", name: "操作人员" }
              ],
              "充值记录"
            );
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
